package com.jcl.recruit.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.resume.mapper.ResumeExternalMsgMapper;
import com.jcl.recruit.resume.model.ResumeExternalMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName ResumeExternalMsgLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/10/15 14:05
 * @Version 1.0
 **/
@Component
public class ResumeExternalMsgLogic implements ResumeExternalMsgMapper {

    @Autowired
    private ResumeExternalMsgMapper resumeExternalMsgMapper;

    public void changeExternalSearchResumeMsg(Integer resumeId,
                       String from,
                       String context,
                       String externalId){
        //List<ResumeExternalMsg> list = resumeExternalMsgMapper.findListByResumeId(resumeId,
        //        Constants.ResumeExternalInfo.TYPE_SEARCH_RESUME);
        //if(CollectionUtils.isEmpty(list)){
            ResumeExternalMsg msg = new ResumeExternalMsg();
            msg.setContext(ResumeExternalMsg.encode(context));
            msg.setSource(from);
            msg.setExternalId(externalId);
            msg.setResumeId(resumeId);
            msg.setCategory( Constants.ResumeExternalInfo.TYPE_SEARCH_RESUME);
            resumeExternalMsgMapper.add(msg);
        //}
    }

    public void changeExternalResumeMsg(Integer resumeId,
                                              String from,
                                              String context,
                                              String externalId){
        List<ResumeExternalMsg> list = resumeExternalMsgMapper.findListByResumeId(resumeId,
                Constants.ResumeExternalInfo.TYPE_RESUME);
        if(CollectionUtils.isEmpty(list)){
            ResumeExternalMsg msg = new ResumeExternalMsg();
            msg.setContext(ResumeExternalMsg.encode(context));
            msg.setSource(from);
            msg.setExternalId(externalId);
            msg.setResumeId(resumeId);
            msg.setCategory(Constants.ResumeExternalInfo.TYPE_RESUME);
            resumeExternalMsgMapper.add(msg);
        }
    }

    @Override
    public List<ResumeExternalMsg> findListByType(Integer type) {
        return resumeExternalMsgMapper.findListByType(type);
    }

    @Override
    public List<ResumeExternalMsg> findListByResumeIds(List<Integer> resumeIds, Integer type) {
        return resumeExternalMsgMapper.findListByResumeIds(resumeIds, type);
    }

    @Override
    public List<ResumeExternalMsg> findListByResumeId(int resumeId, Integer type) {
        return resumeExternalMsgMapper.findListByResumeId(resumeId, type);
    }

    @Override
    public int add(ResumeExternalMsg resumeExternalMsg) {
        return resumeExternalMsgMapper.add(resumeExternalMsg);
    }
}
